/**
 * 
 */
package com.java.test.user.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.test.controller.BaseController;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.user.dto.DrawingChannelInfo;
import com.java.test.user.dto.DrawingTypeInfo;
import com.java.test.user.service.DrawingMangeService;
import com.java.test.util.HttpErrorCode;
import com.java.test.util.JsonResult;

/**
 * @author 提款类型提款渠道
 *
 */
@RestController
@RequestMapping("/drawing")
public class DrawingMangeController extends BaseController {

	@Autowired
	private DrawingMangeService drawingMangeService;

	@RequestMapping("/drawingTypeList")
	public JsonResult drawingTypeList() {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<DrawingTypeInfo> list = drawingMangeService.selectdrawingList();
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/selectdrawingtypeInfobyId")
	public JsonResult selectdrawingtypeInfobyId(@RequestBody DrawingTypeInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			DrawingTypeInfo infos = drawingMangeService.selectdrawingtypeInfobyId(info);
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 添加提款类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/adddrawingTypeInfo")
	public JsonResult adddrawingTypeInfo(@RequestBody DrawingTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.insertdrawingInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-添加提款类型");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改提款类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatedrawingInfo")
	public JsonResult updatedrawingInfo(@RequestBody DrawingTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.updatedrawingInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-修改提款类型");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改提款类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatedrawingsortInfo")
	public JsonResult updatedrawingsortInfo(@RequestBody DrawingTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.updatedrawingsortInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-提款类型排序修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 删除提款类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deletedrawingInfo")
	public JsonResult deletedrawingInfo(@RequestBody DrawingTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			//  查看该提款类型是否有提款渠道
			
			int j  = drawingMangeService.selectdrawingchanbyTypeId(info.getId());
			
			if(j>0) {
				js.setCode(HttpErrorCode.TYPEISEXITSCHANNEL.getCode());
				js.setMessage(HttpErrorCode.TYPEISEXITSCHANNEL.getContent());
				return js;
			}
			
			int i = drawingMangeService.deletedrawingInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-提款类型排序修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	// --------------提款渠道 -------------------------------

	@RequestMapping("/selectdrawingchannelList")
	public JsonResult selectdrawingchannelList(@RequestBody DrawingChannelInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<DrawingChannelInfo> list = drawingMangeService.selectdrawingchannelList(info);
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/selectdrawingchannelInfobyId")
	public JsonResult selectdrawingchannelInfobyId(@RequestBody DrawingChannelInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			DrawingChannelInfo infos = drawingMangeService.selectdrawingchannelInfobyId(info);
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 添加提款渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/insertdrawingchannelInfo")
	public JsonResult insertdrawingchannelInfo(@RequestBody DrawingChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			info.setAddPeople(user.getLoginAccout());
			int i = drawingMangeService.insertdrawingchannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-添加提款渠道");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改提款渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatedrawingchannelInfo")
	public JsonResult updatedrawingchannelInfo(@RequestBody DrawingChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.updatedrawingchannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-修改提款类型");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改提款类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatedrawingchannelsortInfo")
	public JsonResult updatedrawingchannelsortInfo(@RequestBody DrawingChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.updatedrawingchannelsortInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-提款渠道排序修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 删除提款渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deletedrawingchannelInfo")
	public JsonResult deletedrawingchannelInfo(@RequestBody DrawingChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = drawingMangeService.deletedrawingchannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "会员管理-提款类型排序修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

}
